package org.example.controller.singleProject;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.example.model.common.PageResponseDto;
import org.example.model.common.ResponseResult;
import org.example.model.workItem.dtos.WorkItemDto;
import org.example.model.workItem.vos.ModifyWorkItemVo;
import org.example.model.workItem.vos.SearchWorkItemVo;
import org.example.controller.common.permission.PermissionControl;
import org.example.service.workItem.WorkItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 工作项表现层
 */
@CrossOrigin
@RestController
@RequestMapping("/work-item")
@Api(value = "工作项接口", tags = {"工作项接口"})
@PermissionControl(Parent = "项目管理", Name = "工作项", Order = 1)
public class WorkItemController {

    @Autowired
    private WorkItemService workItemService;

    /**
     * 添加一条工作项
     * @param modifyWorkItemVo 要添加或修改的工作项信息
     */
    @PostMapping
    @ApiOperation("添加一条工作项")
    @PermissionControl(Parent = "工作项", Name = "添加", Order = 1)
    public ResponseResult<Boolean> AddWorkItem(@RequestBody ModifyWorkItemVo modifyWorkItemVo){
        return workItemService.InsertWorkItem(modifyWorkItemVo);
    }

    /**
     * 根据id修改一条工作项
     * @param modifyWorkItemVo 要添加或修改的工作项信息
     */
    @PutMapping
    @ApiOperation("根据id修改一条工作项")
    @PermissionControl(Parent = "工作项", Name = "修改", Order = 3)
    public ResponseResult<Boolean> UpdateWorkItem(@RequestBody ModifyWorkItemVo modifyWorkItemVo){
        return workItemService.UpdateWorkItemById(modifyWorkItemVo);
    }

    /**
     * 根据id删除一条工作项
     * @param id 工作项id
     */
    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除一条工作项")
    @PermissionControl(Parent = "工作项", Name = "删除", Order = 2)
    public ResponseResult<Boolean> DeleteWorkItemById(@PathVariable Integer id){
        return workItemService.DeleteWorkItemById(id);
    }

    /**
     * 根据条件分页获取工作项列表
     * @param searchWorkItemVo 查询条件
     */
    @GetMapping("/workItem-list")
    @ApiOperation("根据条件分页获取工作项列表")
    @PermissionControl(Parent = "工作项", Name = "查询", Order = 4)
    public ResponseResult<PageResponseDto<List<WorkItemDto>>> GetWorkItemByPage(SearchWorkItemVo searchWorkItemVo) {
        return workItemService.SelectWorkItemByPage(searchWorkItemVo);
    }
}
